package pers.amos.eshop.advance.product.mapper;

import org.apache.ibatis.annotations.*;
import pers.amos.eshop.advance.product.model.Brand;

import java.util.List;


@Mapper
public interface BrandMapper {

    @Insert("INSERT INTO brand(name,description) VALUES(#{name},#{description})")
    @Options(keyColumn = "id", keyProperty = "id", useGeneratedKeys = true)
    void add(Brand brand);

    @Update("UPDATE brand SET name=#{name},description=#{description} WHERE id=#{id}")
    void update(Brand brand);

    @Delete("DELETE FROM brand WHERE id=#{id}")
    void delete(Long id);

    @Select("SELECT * FROM brand WHERE id=#{id}")
    Brand findById(Long id);

    /**
     * 批量查询来优化远程调用的性能
     * @param ids 所有需要查询的 id 以逗号分割
     * @return
     */
    @Select("SELECT * FROM brand WHERE id in (${ids})")
    List<Brand> findBrandListByIds(@Param("ids") String ids);

}
